import { lazy, Suspense } from 'react';
import { createBrowserRouter, Navigate } from 'react-router-dom';
import Login from '@/pages/Login';
import Home from '@/pages/Home';
import Loyout from '@/pages/Layout';
import Loading from '@/pages/components/Loading';
import orderRouters from './moudles/order';
import vipRouters from './moudles/vip';
const NotFound = lazy(() => import('@/pages/NotFound'));

// * 创建路由表
export const router = [
  {
    path: '/',
    element: <Navigate to="/home" />, // 重定向
  },
  {
    path: '/login',
    element: <Login />,
  },
  {
    element: <Loyout />,
    children: [{ path: 'home', element: <Home />, meta: { name: '首页总览' } }, ...orderRouters, ...vipRouters],
  },
  {
    path: '*',
    element: (
      <Suspense fallback={<Loading />}>
        <NotFound />
      </Suspense>
    ),
  },
];

export default createBrowserRouter(router);
